////
////  CDRequestAPI.swift
////  CandyDate
////
////  Created by zolobdz on 2017/12/19.
////  Copyright © 2017年 HeChao. All rights reserved.
////
//
//import UIKit
//import Moya
//import Result
//
//private let ShowHudKey = "ShowHudKey"
//
//public enum CDRequestAPI{
//    
//
//    case modifyPassword(ShowHudKey: Bool, uid: String,password: String, oldPassword: String) // 修改密码
//    
//}
//
//protocol CDNetworkHud {
//    var canShow: Bool { get }
//}
//
//extension CDRequestAPI : CDNetworkHud
//{
//    var canShow: Bool {
//        if let parameters = parameters,!parameters.isEmpty
//        {
//            switch self{
//            case .modifyPassword(let ShowHudKey, _, _, _):
//                return ShowHudKey
//            }
////            if let show = parameters[ShowHudKey] as? Bool,show
////            {
////                return true
////            }
//        }
//        return false
//    }
//}
//
//extension CDRequestAPI : TargetType{
//    public var headers: [String : String]? {
//        return [
//            "Content-Type" : "application/x-www-form-urlencoded",
////            "Api-Version" : API_Version
//        ]
//    }
//    
//    
//    public var baseURL: URL {
//        return URL(string: CDNetWorkService.shared.currentEnvironment.baseURL)!
//    }
//    
//    public var path: String {
//        switch self {
//        case .modifyPassword:
//            return "user/updatePwdByUid"
//        }
//    }
//    
//    public var method: Moya.Method {
//        switch self {
//        case .modifyPassword:
//            return .get
//        default:
//            return .post
//        }
//    }
//    
//    
//    public var parameters: [String : Any]? {
//        switch self {
//        case .modifyPassword(_ , let uid, let password, let oldPassword):
//            return ["uid": uid,
//                    "newPwd": password,
//                    "oldPwd": oldPassword,]
//        
//        }
//    }
//    
//    public var sampleData: Data {
//        return "{\"rc\":10,\"msg\":\"\",\"data\":{}}".data(using: .utf8)!
//        //        return "[{\"rc\": \"Repo Name\"}]".data(using: String.Encoding.utf8)!
//    }
//    
//    public var parameterEncoding: ParameterEncoding {
//        return URLEncoding.default
//    }
//    
//    public var task: Task {
//        /*
//         case request
//         /// An upload task.
//         case upload(UploadType)
//         /// A download task.
//         case download(DownloadType)
//         */
//        return .requestPlain
//    }
//}
//
//
////MARK: config
//
//let requestTimeoutClosure = { (endpoint: Endpoint, done: @escaping MoyaProvider<CDRequestAPI>.RequestResultClosure) in
////    guard var request = endpoint.urlRequest else { return }
////    request.timeoutInterval = 30    //设置请求超时时间
////    done(.success(request))
//}
//
//
//
////func endpointMapping<Target: TargetType>(target: Target) -> Endpoint {
//////    CDUtility.log("请求连接：\(target.baseURL)\(target.path) \n方法：\(target.method)\n参数：\(String(describing: target.parameters)) ")
////    //在这里设置你的HTTP头部信息
////    return MoyaProvider.defaultEndpointMapping(for: target).adding(newHTTPHeaderFields: [
////        "Content-Type" : "application/x-www-form-urlencoded",
////        "Api-Version" : API_Version
////        ])
////}
//
//let networkPlugin = NetworkActivityPlugin { (type,target) in
//    switch type {
//    case .began:
//        /// 状态栏转圈
//        DispatchQueue.main.async {
//            UIApplication.shared.isNetworkActivityIndicatorVisible = true
//        }
//        
//    case .ended:
//        /// 状态栏停止转圈
//        DispatchQueue.main.async {
//            UIApplication.shared.isNetworkActivityIndicatorVisible = false
//        }
//    }
//}
//
//class RequestLoadingPlugin: PluginType {
//    
//    func willSend(_ request: RequestType, target: TargetType) {
//        CDUtility.log("开始请求")
//        
//        if let api = target as? CDRequestAPI,api.canShow
//        {
//            CDUtility.showHud()
//        }
//    }
//    
//    func didReceive(_ result: Result<Response, MoyaError>, target: TargetType) {
//        CDUtility.log("结束请求")
//        if let api = target as? CDRequestAPI,api.canShow
//        {
//            CDUtility.hidHud()
//        }
//    }
//}
